<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi
 *
 */

class NotificationsController extends AppController {

    /**
     * Define $name
     *
     */
    var $name = 'Notifications';
    /**
     * Define $helpers
     *
     */
    var $helpers = array('Html', 'Form');

    /**
     * Describe index
     *
     * @return null
     */
    function index() {
        $this->Notification->recursive = 0;
        $this->set('notifications', $this->paginate());
    }

    /**
     * Describe view
     *
     * @param $id
     * @return null
     */
    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid Notification.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('notification', $this->Notification->read(null, $id));
    }

    /**
     * Describe add
     *
     * @return null
     */
    function add() {
        if (!empty($this->data)) {
            $this->Notification->create();
            if ($this->Notification->save($this->data)) {
                $this->Session->setFlash(__('The Notification has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Notification could not be saved. Please, try again.', true));
            }
        }
        $meetings = $this->Notification->Meeting->find('list');
        $this->set(compact('meetings'));
    }

    /**
     * Describe edit
     *
     * @param $id
     * @return null
     */
    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Notification', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Notification->save($this->data)) {
                $this->Session->setFlash(__('The Notification has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Notification could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Notification->read(null, $id);
        }
        $meetings = $this->Notification->Meeting->find('list');
        $this->set(compact('meetings'));
    }

    /**
     * Describe delete
     *
     * @param $id
     * @return null
     */
    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Notification', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Notification->del($id);
        $this->Session->setFlash(__('Notification deleted', true));
        $this->redirect(array('action'=>'index'));
    }

}
?>
